home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CDICTION
/
CTESTDIC.C
< prev
next >
Wrap
Text File
|
1990-01-12
|
1KB
|
54 lines
#include "CTestDict.h"
#include "CPascalString.h"
#include "TBUtilities.h"
/* map and compare procs for dictionary */
uInt32 MapKey( void *key); /* map string to unsigned long */
Boolean CompareKeys( void *key1, void *key2); /* compare two keys */
/********************************************************************/
Boolean CTestDict::ITestDict( void )
{
CDictionary::IDictionary( sizeof(Str20), MapKey, CompareKeys, 0);
} /* CTestDict::ITestDict */
/********************************************************************/
/* map and compare procs for dictionary */
uInt32 MapKey( void *key) /* map string to unsigned long */
{
Str20 copy;
register unsigned char *s;
register uInt32 sum = 1;
register Int16 i, triplets;
register unsigned short ch;
Int16 length;
pStrCopy( key, copy);
UprString( copy, FALSE);
s = copy;
length = *s++;
triplets = length / 3;
for (i = 0; i < triplets; i++)
{
sum *= *s++;
ch = *s++;
sum *= ch << 1;
ch = *s++;
sum *= ch << 2;
}
for (i = triplets * 3; i < length; i++)
sum *= *s++;
sum >>= 8;
return sum;
}
Boolean CompareKeys( void *key1, void *key2) /* compare two keys */
{
return EqualString( key1, key2, FALSE, FALSE);
}